<template>
  <ul>
    <li @click="handleDel(item.id)" v-for="item in state.arr" :key="item.id">
      {{ item.name }}
    </li>
  </ul>
</template>
<script>
import { reactive } from 'vue'
export default {
  setup() {
    // #1 定义 reactive 包装后的响应式数据
    const state = reactive({
      arr: [
        {
          id: 0,
          name: 'ifer',
        },
        {
          id: 1,
          name: 'elser',
        },
        {
          id: 2,
          name: 'xxx',
        },
      ],
    })
    const handleDel = (id) => {
      // 根据 id 找索引
      const idx = state.arr.findIndex((item) => item.id === id)
      // 根据索引去删除
      state.arr.splice(idx, 1)
    }
    // #2 并导出
    return {
      state,
      handleDel,
    }
  },
}
</script>
